/*
 * Home.java
 *
 * Created on January 29, 2007, 11:11 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package ge.info.pages;



import ge.info.domain.Organization;
import ge.info.domain.Service;
import ge.ktapestry.pages.BasePageExt;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.event.PageBeginRenderListener;
import org.apache.tapestry.event.PageEvent;

import java.util.List;
import org.apache.hivemind.util.PropertyUtils;
import org.apache.tapestry.IPage;
import org.apache.tapestry.annotations.InjectState;

public abstract class OrgSearch extends BasePageExt implements PageBeginRenderListener
{

    @InjectState("service")
    public abstract Service getService();

    public abstract void setService(Service service);

    @Persist
    public abstract Organization getOrganization();

    public abstract void setOrganization(Organization organization);

    public void pageBeginRender(PageEvent event)
    {
         

            if (getOrganization() == null)
            {
                setOrganization(new Organization());
                
            }
         
    }

    public void search(IRequestCycle cycle)
    {
        List<Organization> list = getDbExecutor().searchOrganizations(getOrganization());

        if (list != null)
        {
            IPage page = cycle.getPage("OrgResults");
            PropertyUtils.write(page, "organizations", list);
            setOrganization(new Organization());
            cycle.activate(page);
        }
        setOrganization(null);
    }
    public void clear(IRequestCycle cycle)
    {
        setOrganization(new Organization());
    }
}
